package com.it.controller;


import com.it.pojo.Result;
import com.it.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileUploadController {


    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        //把文件内容存储到本地磁盘
        String orginalFilename =  file.getOriginalFilename();

        //保证名字统一 UUID随机生成数
        String filename = UUID.randomUUID().toString()+orginalFilename.substring(orginalFilename.lastIndexOf("."));
//        file.transferTo(new File("D:\\2025spring\\big"+filename));
        String url = AliOssUtil.uploadFile(filename,file.getInputStream());
        return Result.success(url);
    }
}
